package controllers

import (
	"discuz/libs"
	"discuz/models"
	"fmt"
	"github.com/astaxie/beego"
	"strconv"
	"time"
)

type WeChatController struct {
	beego.Controller
}

//@router /dis [get]
func (c *WeChatController) Dis() {
	postTableid := models.GetMaxId()
	fmt.Println(postTableid.Id)
	c.Ctx.WriteString(strconv.Itoa(postTableid.Id))
}

//@router /ela [get,post]
func (c *WeChatController) Ela() {
	id := c.GetString("id")
	libs.ElaIsExists("jike", "user", id)
	c.Ctx.WriteString("success")
}

//@router /wechat [post]
func (c *WeChatController) Get() {
	var wc models.WeChat
	msg := make(map[string]interface{})
	msg["status"] = false
	msg["msg"] = "error 1"
	msg["code"] = -1
	if c.GetString("msgTitle") == "" {
		c.Data["json"] = msg
		c.ServeJSON()
	}
	wc.MsgTitle = c.GetString("msgTitle")
	wc.MsgContent = c.GetString("msgContent")
	wc.MsgTime = c.GetString("msgTime")
	wc.MsgTime = c.GetString("msgTime")
	wc.MsgLink = c.GetString("msgLink")
	wc.NickName = c.GetString("nickName")
	libs.AddElaWeChat(&wc)

	var fp models.ForumPost
	postTableid := models.GetMaxId()
	tid := models.GetMaxTid()
	fp.Id = postTableid.Id + 1
	fp.Fid = 65
	fp.Tid = tid.Tid + 1
	fp.First = 1
	fp.Author = "hahaxi"
	fp.Authorid = 1
	fp.Usesig = 1
	fp.Htmlon = 1
	fp.Subject = c.GetString("msgTitle")
	fp.Dateline = time.Now().Unix()
	fp.Message = c.GetString("msgContent")
	fp.Useip = "127.0.0.1"
	id, _ := models.AddForumPost(&fp)
	fmt.Println(id)

	var fpt models.PostTableid
	fpt.Id = postTableid.Id + 1
	models.AddMaxId(&fpt)

	var ft models.ForumThread
	ft.Fid = 65
	ft.Author = "hahaxi"
	ft.Authorid = 1
	ft.Subject = c.GetString("msgTitle")
	ft.Dateline = time.Now().Unix()
	ft.Lastpost = time.Now().Unix()
	ft.Lastposter = "hahaxi"
	models.AddForumThread(&ft)

	msg["status"] = true
	msg["msg"] = "success"
	msg["code"] = 200
	c.Data["json"] = msg
	c.ServeJSON()
}
